package com.jp.knowledge.adapter.attention;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.model.attention.AttentionGroupDetailModel;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.base.RecycleVHolder;

import java.util.List;

/**
 * Created by 528787067@qq.com on 2017/3/18.
 */

public class AttentionGroupDetailAdapter extends RecycleVAdapter<AttentionGroupDetailModel> implements View.OnClickListener {

    public AttentionGroupDetailAdapter(Context context, @NonNull List<AttentionGroupDetailModel> list) {
        super(context, list);
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.attention_item_view;
    }

    @Override
    public void onBind(RecycleVHolder holder, int position) {
        AttentionGroupDetailModel data = getData(position);
        holder.get(R.id.icon).setVisibility(View.GONE);
        holder.get(R.id.descritption).setVisibility(View.GONE);
        holder.get(R.id.more_info_view).setVisibility(View.GONE);
        holder.setTextView(R.id.title, data.getTitle()+"("+data.getConditionNum()+")");
        TextView newNum = holder.getTextView(R.id.new_num);
        newNum.setText(data.getNewNum()+"");
        if(data.getNewNum() > 0)
            newNum.setTextColor(mContext.getResources().getColor(R.color.orange));
        else
            newNum.setTextColor(mContext.getResources().getColor(R.color.font_gray_think));
        holder.setTextView(R.id.new_text, data.getCountNum()+"数据");
        holder.get(R.id.main_view).setTag(position);
        holder.get(R.id.change_btn).setTag(position);
        holder.get(R.id.delete_btn).setTag(position);
        holder.get(R.id.main_view).setOnClickListener(this);
        holder.get(R.id.change_btn).setOnClickListener(this);
        holder.get(R.id.delete_btn).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.main_view:
                if(this.itemCallback != null)
                    this.itemCallback.onItemClick((int)v.getTag());
                break;
            case R.id.change_btn:
                if(this.itemCallback != null)
                    this.itemCallback.onChangedClick((int)v.getTag());
                break;
            case R.id.delete_btn:
                if(this.itemCallback != null)
                    this.itemCallback.onDeleteClick((int)v.getTag());
                break;
        }
    }

    private OnItemCallback itemCallback;
    public void setOnItemCallback(OnItemCallback callback){
        this.itemCallback = callback;
    }

    public interface OnItemCallback{
        void onItemClick(int position);
        void onChangedClick(int position);
        void onDeleteClick(int position);
    }
}
